package cn.wolfcode.crm.web.interceptor;

import cn.wolfcode.crm.util.UserContext;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
       //拿到session中的employee
        //Object employee_in_session = request.getSession().getAttribute("EMPLOYEE_IN_SESSION");//登录后将employee信息放session
        Object employee_in_session = UserContext.getEmployee();
        //如果对象为空,说明没有登录过,去登录页面,不用带数据 用重定向
        if(employee_in_session == null){
            response.sendRedirect("/login.jsp");//
            return false;
        }
        //有数据就放行
        return true;
    }
}
